package com.example.doer.reading.AppActivities;



import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.ab.fragment.AbFragment;
import com.example.doer.reading.AppDataModel.MyInfoList;
import com.example.doer.reading.AppAdapters.MyInfoListViewAdapter;
import com.example.doer.reading.R;

import java.util.ArrayList;
import java.util.List;

public class FragmentFour extends AbFragment{
    private FragmentManager fragmentManager;


    public FragmentFour(){

    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_four,null);
        /*第一个ListView*/
        ListView listView = (ListView)view.findViewById(R.id.MyInfoList);
        List<MyInfoList> list = new ArrayList<MyInfoList>();

        list.add(new MyInfoList(R.mipmap.ic_launcher,"点击登陆/注册"));
        list.add(new MyInfoList(R.mipmap.ic_launcher,"个人主页" ));
        MyInfoListViewAdapter myInfoListViewAdapter = new MyInfoListViewAdapter(getActivity(),list,R.layout.mylist);

        listView.setAdapter(myInfoListViewAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if(position == 0)
                {

//                    LoginFragment fragmentLogin = new LoginFragment();
//                    fragmentManager.beginTransaction().add(R.id.realtabcontent,fragmentLogin).commit();
//                    fragmentManager.beginTransaction().addToBackStack(null).hide((AbFragment)mainActivity.getFragmentList().get(3)).commit();
//                    mainActivity.getFragmentList().get(3).setUserVisibleHint(false);
//                    fragmentManager.beginTransaction().show(fragmentLogin).commit();
//                    fragmentLogin.setUserVisibleHint(true);
//                    getActivity().findViewById(R.id.main_bottom).setVisibility(View.INVISIBLE);
                    //fm.beginTransaction().hide()
                    LoginFragment fragmentLogin = new LoginFragment();
                    FragmentManager fm = getFragmentManager();
                    FragmentTransaction ft=fm.beginTransaction();
                    //ft.addToBackStack(null).replace(R.id.realtabcontent,fragmentLogin);
                    //ft.commit();

                    ft.add(R.id.realtabcontent,fragmentLogin).commit();
                    fm.beginTransaction().addToBackStack(null).commit();
                    fm.beginTransaction().hide(FragmentFour.this).commit();
                    fm.beginTransaction().show(fragmentLogin).commit();
                    getActivity().findViewById(R.id.main_bottom).setVisibility(View.INVISIBLE);
                }
            }
        });
        ListView listView1 = (ListView)view.findViewById(R.id.ListView1);
        List<MyInfoList> list1 = new ArrayList<MyInfoList>();

        list1.add(new MyInfoList(R.mipmap.ic_launcher,"关注   提问   回答"));
        list1.add(new MyInfoList(R.mipmap.ic_launcher,"收藏夹" ));
        list1.add(new MyInfoList(R.mipmap.ic_launcher,"最近浏览" ));
        list1.add(new MyInfoList(R.mipmap.ic_launcher,"已购图书" ));
        MyInfoListViewAdapter myInfoListViewAdapter1 = new MyInfoListViewAdapter(getActivity(),list1,R.layout.mylist);

        listView1.setAdapter(myInfoListViewAdapter1);


        ListView listView2 = (ListView)view.findViewById(R.id.ListView2);
        List<MyInfoList> list2 = new ArrayList<MyInfoList>();

        list2.add(new MyInfoList(R.mipmap.ic_launcher,"夜间模式"));
        list2.add(new MyInfoList(R.mipmap.ic_launcher,"设置"));
        MyInfoListViewAdapter myInfoListViewAdapter2 = new MyInfoListViewAdapter(getActivity(),list2,R.layout.mylist);

        listView2.setAdapter(myInfoListViewAdapter2);
        return view;
    }

}
